﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="VehicleTransactionFilterTests.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the VehicleTransactionFilterTests type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Data.Tests.Filters
{
    using System.Data.Objects;
    using System.Linq;
    using Data.Filters;
    using Entities;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// Defines the <seealso cref="Hisaab.Data.Tests.Filters.VehicleTransactionFilterTests"/> type.
    /// </summary>
    [TestClass]
    public class VehicleTransactionFilterTests
    {
        /// <summary>
        /// Mock database
        /// </summary>
        private readonly IObjectSet<VehicleTransaction> _mockObjectSet = new MockObjectSet<VehicleTransaction>();

        /// <summary>
        /// Initializes a new instance of the <see cref="VehicleTransactionFilterTests"/> class.
        /// </summary>
        public VehicleTransactionFilterTests()
        {
            _mockObjectSet.AddObject(new VehicleTransaction { Id = 1, Fill = 12.1M, Fuel = 15.2M, Milage = 15648, Oil = 156.2M, Service = 1.34M, Tires = 154.2M, TransactionId = 45, VehicleId = 56 });
            _mockObjectSet.AddObject(new VehicleTransaction { Id = 2, Fill = 54.3M, Fuel = 25.9M, Milage = 12547, Oil = 256.1M, Service = 2.67M, Tires = 124.6M, TransactionId = 67, VehicleId = 78 });
            _mockObjectSet.AddObject(new VehicleTransaction { Id = 3, Fill = 98.6M, Fuel = 03.7M, Milage = 16482, Oil = 100.0M, Service = 3.84M, Tires = 135.7M, TransactionId = 89, VehicleId = 90 });
        }

        /// <summary>
        /// Vehicles the transaction filter should return everything if the object to comare is null.
        /// </summary>
        [TestMethod]
        public void VehicleTransactionFilterShouldReturnEverythingIfTheObjectToComareIsNull()
        {
            var result = _mockObjectSet.Filter(null).ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Count());
        }

        /// <summary>
        /// Vehicles the transaction filter should return everything if the object to comare is uninitialized.
        /// </summary>
        [TestMethod]
        public void VehicleTransactionFilterShouldReturnEverythingIfTheObjectToComareIsUninitialized()
        {
            var result = _mockObjectSet.Filter(new VehicleTransaction()).ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Count());
        }

        /// <summary>
        /// Vehicles the transaction filter should return object filtered by id.
        /// </summary>
        [TestMethod]
        public void VehicleTransactionFilterShouldReturnObjectFilteredById()
        {
            var result = _mockObjectSet.Filter(new VehicleTransaction { Id = 2 }).ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(2, result[0].Id);
            Assert.AreEqual(54.3M, result[0].Fill);
            Assert.AreEqual(25.9M, result[0].Fuel);
            Assert.AreEqual(12547, result[0].Milage);
            Assert.AreEqual(256.1M, result[0].Oil);
            Assert.AreEqual(2.67M, result[0].Service);
            Assert.AreEqual(124.6M, result[0].Tires);
            Assert.AreEqual(67, result[0].TransactionId);
            Assert.AreEqual(78, result[0].VehicleId);
        }

        /// <summary>
        /// Filters the should return object filtered by title.
        /// </summary>
        [TestMethod]
        public void VehicleTransactionFilterShouldReturnObjectFilteredByFill()
        {
            var result = _mockObjectSet.Filter(new VehicleTransaction { Fill = 54.3M }).ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(2, result[0].Id);
            Assert.AreEqual(54.3M, result[0].Fill);
            Assert.AreEqual(25.9M, result[0].Fuel);
            Assert.AreEqual(12547, result[0].Milage);
            Assert.AreEqual(256.1M, result[0].Oil);
            Assert.AreEqual(2.67M, result[0].Service);
            Assert.AreEqual(124.6M, result[0].Tires);
            Assert.AreEqual(67, result[0].TransactionId);
            Assert.AreEqual(78, result[0].VehicleId);
        }

        /// <summary>
        /// Vehicles the transaction filter should return object filtered by fuel.
        /// </summary>
        [TestMethod]
        public void VehicleTransactionFilterShouldReturnObjectFilteredByFuel()
        {
            var result = _mockObjectSet.Filter(new VehicleTransaction { Fuel = 25.9M }).ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(2, result[0].Id);
            Assert.AreEqual(54.3M, result[0].Fill);
            Assert.AreEqual(25.9M, result[0].Fuel);
            Assert.AreEqual(12547, result[0].Milage);
            Assert.AreEqual(256.1M, result[0].Oil);
            Assert.AreEqual(2.67M, result[0].Service);
            Assert.AreEqual(124.6M, result[0].Tires);
            Assert.AreEqual(67, result[0].TransactionId);
            Assert.AreEqual(78, result[0].VehicleId);
        }

        /// <summary>
        /// Vehicles the transaction filter should return object filtered by milage.
        /// </summary>
        [TestMethod]
        public void VehicleTransactionFilterShouldReturnObjectFilteredByMilage()
        {
            var result = _mockObjectSet.Filter(new VehicleTransaction { Milage = 12547 }).ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(2, result[0].Id);
            Assert.AreEqual(54.3M, result[0].Fill);
            Assert.AreEqual(25.9M, result[0].Fuel);
            Assert.AreEqual(12547, result[0].Milage);
            Assert.AreEqual(256.1M, result[0].Oil);
            Assert.AreEqual(2.67M, result[0].Service);
            Assert.AreEqual(124.6M, result[0].Tires);
            Assert.AreEqual(67, result[0].TransactionId);
            Assert.AreEqual(78, result[0].VehicleId);
        }

        /// <summary>
        /// Vehicles the transaction filter should return object filtered by oil.
        /// </summary>
        [TestMethod]
        public void VehicleTransactionFilterShouldReturnObjectFilteredByOil()
        {
            var result = _mockObjectSet.Filter(new VehicleTransaction { Oil = 256.1M }).ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(2, result[0].Id);
            Assert.AreEqual(54.3M, result[0].Fill);
            Assert.AreEqual(25.9M, result[0].Fuel);
            Assert.AreEqual(12547, result[0].Milage);
            Assert.AreEqual(256.1M, result[0].Oil);
            Assert.AreEqual(2.67M, result[0].Service);
            Assert.AreEqual(124.6M, result[0].Tires);
            Assert.AreEqual(67, result[0].TransactionId);
            Assert.AreEqual(78, result[0].VehicleId);
        }

        /// <summary>
        /// Vehicles the transaction filter should return object filtered by service.
        /// </summary>
        [TestMethod]
        public void VehicleTransactionFilterShouldReturnObjectFilteredByService()
        {
            var result = _mockObjectSet.Filter(new VehicleTransaction { Service = 2.67M }).ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(2, result[0].Id);
            Assert.AreEqual(54.3M, result[0].Fill);
            Assert.AreEqual(25.9M, result[0].Fuel);
            Assert.AreEqual(12547, result[0].Milage);
            Assert.AreEqual(256.1M, result[0].Oil);
            Assert.AreEqual(2.67M, result[0].Service);
            Assert.AreEqual(124.6M, result[0].Tires);
            Assert.AreEqual(67, result[0].TransactionId);
            Assert.AreEqual(78, result[0].VehicleId);
        }

        /// <summary>
        /// Vehicles the transaction filter should return object filtered by tires.
        /// </summary>
        [TestMethod]
        public void VehicleTransactionFilterShouldReturnObjectFilteredByTires()
        {
            var result = _mockObjectSet.Filter(new VehicleTransaction { Tires = 124.6M }).ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(2, result[0].Id);
            Assert.AreEqual(54.3M, result[0].Fill);
            Assert.AreEqual(25.9M, result[0].Fuel);
            Assert.AreEqual(12547, result[0].Milage);
            Assert.AreEqual(256.1M, result[0].Oil);
            Assert.AreEqual(2.67M, result[0].Service);
            Assert.AreEqual(124.6M, result[0].Tires);
            Assert.AreEqual(67, result[0].TransactionId);
            Assert.AreEqual(78, result[0].VehicleId);
        }

        /// <summary>
        /// Vehicles the transaction filter should return object filtered by transaction id.
        /// </summary>
        [TestMethod]
        public void VehicleTransactionFilterShouldReturnObjectFilteredByTransactionId()
        {
            var result = _mockObjectSet.Filter(new VehicleTransaction { TransactionId = 67 }).ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(2, result[0].Id);
            Assert.AreEqual(54.3M, result[0].Fill);
            Assert.AreEqual(25.9M, result[0].Fuel);
            Assert.AreEqual(12547, result[0].Milage);
            Assert.AreEqual(256.1M, result[0].Oil);
            Assert.AreEqual(2.67M, result[0].Service);
            Assert.AreEqual(124.6M, result[0].Tires);
            Assert.AreEqual(67, result[0].TransactionId);
            Assert.AreEqual(78, result[0].VehicleId);
        }

        /// <summary>
        /// Vehicles the transaction filter should return object filtered by vehicle id.
        /// </summary>
        [TestMethod]
        public void VehicleTransactionFilterShouldReturnObjectFilteredByVehicleId()
        {
            var result = _mockObjectSet.Filter(new VehicleTransaction { VehicleId = 78 }).ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(2, result[0].Id);
            Assert.AreEqual(54.3M, result[0].Fill);
            Assert.AreEqual(25.9M, result[0].Fuel);
            Assert.AreEqual(12547, result[0].Milage);
            Assert.AreEqual(256.1M, result[0].Oil);
            Assert.AreEqual(2.67M, result[0].Service);
            Assert.AreEqual(124.6M, result[0].Tires);
            Assert.AreEqual(67, result[0].TransactionId);
            Assert.AreEqual(78, result[0].VehicleId);
        }

        /// <summary>
        /// Vehicles the transaction filter should return object filtered by combination of fields.
        /// </summary>
        [TestMethod]
        public void VehicleTransactionFilterShouldReturnObjectFilteredByCombinationOfFields()
        {
            var result = _mockObjectSet.Filter(
                new VehicleTransaction { Fill = 98.6M, Fuel = 03.7M, Milage = 16482, Oil = 100.0M, Service = 3.84M, Tires = 135.7M, TransactionId = 89, VehicleId = 90 })
                .ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(3, result[0].Id);
            Assert.AreEqual(98.6M, result[0].Fill);
            Assert.AreEqual(03.7M, result[0].Fuel);
            Assert.AreEqual(16482, result[0].Milage);
            Assert.AreEqual(100.0M, result[0].Oil);
            Assert.AreEqual(3.84M, result[0].Service);
            Assert.AreEqual(135.7M, result[0].Tires);
            Assert.AreEqual(89, result[0].TransactionId);
            Assert.AreEqual(90, result[0].VehicleId);
        }

        /// <summary>
        /// Vehicles the transaction filter should return nothing if mismatching object filtered by combination of fields.
        /// </summary>
        [TestMethod]
        public void VehicleTransactionFilterShouldReturnNothingIfMismatchingObjectFilteredByCombinationOfFields()
        {
            var result = _mockObjectSet.Filter(
                new VehicleTransaction { Fill = 12.1M, Fuel = 15.2M, Milage = 15648, Oil = 256.1M, Service = 2.67M, Tires = 124.6M, TransactionId = 89, VehicleId = 90 })
                .ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count());
        }
    }
}